cmake_minimum_required(VERSION 3.10) # 指定CMake的最低版本要求

# 项目名称和版本
project(VDBServer VERSION 1.0)

# 设置C++标准
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED True)

# 包含目录
include_directories(include)

# 设置可执行文件名称
set(EXECUTABLE_OUTPUT_PATH ${CMAKE_BINARY_DIR}/bin)

# 定义源文件变量
set(SOURCES
    src/faiss_index.cpp
    src/http_server.cpp
    src/index_factory.cpp
    src/logger.cpp
    src/vdb_server.cpp
    src/hnswlib_index.cpp
)

# 查找OpenMP包
find_package(OpenMP REQUIRED)
if(OpenMP_CXX_FOUND)
    set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${OpenMP_CXX_FLAGS}")
endif()

# 添加可执行文件
add_executable(vdb_server ${SOURCES})

# 定义需要链接的库的完整路径
set(FAISS_LIBRARY "/usr/local/lib/libfaiss.so")
set(SPDLOG_LIBRARY "/usr/local/lib/libspdlog.a")
set(OPENBLAS_LIBRARY "/usr/lib/libopenblas.so") # 如果是静态库，使用 .a；如果是动态库，使用 .so

# 链接库
target_link_libraries(vdb_server
    ${OpenMP_CXX_FLAGS} # 链接OpenMP
    ${FAISS_LIBRARY}   # 链接faiss库
    ${SPDLOG_LIBRARY}  # 链接spdlog库
    ${OPENBLAS_LIBRARY} # 链接openblas库
    pthread           # 链接pthread库
)

# 如果需要，可以添加测试
enable_testing()
add_test(NAME TestFaissInstall COMMAND test/test_faiss_install)
